package thread;

/**
 * @author DBX
 * @effect sleep方法要求处理中断异常：InterruptedException
 *          当一个线程调用sleep方法处于阻塞的过程中，该线程的interrupt方法被调用时
 *          该线程会立即解除阻塞，测试会抛出中断异常
 * @date 2021/9/1 0001 - 9:16
 */
public class SleepDemo1 {
    public static void main(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("开始执行");

                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                        System.out.println("中断sleep");
                    }

                System.out.println("执行完");
            }
        });

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 3; i++) {
                    System.out.println(i+1);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                t.interrupt();
            }
        });
        t.start();
        t1.start();
    }
}
